import { DeviceSonTypeEnum, DeviceTypeEnum } from '@/utils/enum/index.js'
import gridList from '../js/grid.js'
import LineList from '../js/line.js'
import AbilityList from '../js/deviceAbility.js'
import MetricsList from '../js/deviceMetrics'
import constantSetList from '../js/constantSetAbility.js'
import ButtonList from '../js/button'
import programConfig from '../js/program'

export default {
  data() {
    return {
      DeviceSonTypeEnum: DeviceSonTypeEnum,
      DeviceTypeEnum: DeviceTypeEnum,
      box1C01And1H01DeviceInfoList: ['1C01', '1H01'],
      box1D01DeviceInfoList: ['1D01'],
      box1E01And1I01DeviceInfoList: ['1E01', '1I01'],
      box1F01And1G01And1J01DeviceInfoList: ['1F01', '1G01', '1J01']
    }
  },

  methods: {
    // 获取设备能力列表
    getDeviceAbilityList(deviceId) {
      const deviceInfo = this.getDeviceInfo(deviceId)
      return AbilityList['box' + deviceInfo + 'AbilityList'] ?? []
    },
    // 获取设备指标列表
    getDeviceMetricsList(deviceId) {
      const deviceInfo = this.getDeviceInfo(deviceId)
      return MetricsList['box' + deviceInfo + 'MetricsList'] ?? []
    },
    // 获取设备监控台曲线列表
    // 1C01 温湿度试验箱 1D01 温度试验箱
    getDeviceMonitoringLineList(deviceId) {
      const deviceInfo = this.getDeviceInfo(deviceId)
      return LineList['box' + deviceInfo + 'LineList'] ?? []
    },
    // 获取设备监控台程序网格列表
    getDeviceMonitoringProgramGridList(deviceId) {
      const deviceInfo = this.getDeviceInfo(deviceId)
      return gridList['box' + deviceInfo + 'ProgramGridList'] ?? []
    },
    // 获取设备监控台定值网格列表
    getDeviceMonitoringConstantGridList(deviceId) {
      const deviceInfo = this.getDeviceInfo(deviceId)
      return gridList['box' + deviceInfo + 'ConstantGridList'] ?? []
    },
    // 获取全部网格列表(用于历史详细数据分页表头)
    getAllGridList(deviceId) {
      const deviceInfo = this.getDeviceInfo(deviceId)
      return gridList['box' + deviceInfo + 'ProgramGridList'] ?? []
    },
    // 获取定值设置列表
    getConstantSetList(deviceId) {
      const deviceInfo = this.getDeviceInfo(deviceId)
      return constantSetList['box' + deviceInfo + 'ConstantSetList'] ?? []
    },
    // 判断运行程序时是否能下发程序号
    judgeRunProgramIsCanIssuedInstructionProgramId(deviceId) {
      const deviceInfo = this.getDeviceInfo(deviceId)
      const notCanIssuedInstructionDeviceInfoList = []
      return !notCanIssuedInstructionDeviceInfoList.includes(deviceInfo)
    },
    // 判断程序管理是否显示
    judgeProgramManagemenIsShow(deviceId) {
      const deviceInfo = this.getDeviceInfo(deviceId)
      const programManagemenIsShowList = []
      return programManagemenIsShowList.includes(deviceInfo)
    },
    // 判断运行程序时是否能下发程序名称
    judgeRunProgramIsCanIssuedInstructionProgramName(deviceId) {
      return false
      // const deviceInfo = this.getDeviceInfo(deviceId)
      // const canIssuedInstructionDeviceInfoList = [
      //   ...this.box1C01And1H01DeviceInfoList,
      //   ...this.box1D01DeviceInfoList,
      //   ...this.box1E01And1I01DeviceInfoList,
      //   ...this.box1F01And1G01DeviceInfoList
      // ]
      // return canIssuedInstructionDeviceInfoList.includes(deviceInfo)
    },
    // 判断跳段时是否有程序编辑功能(程序名)
    hasProgramNameEdit(deviceId) {
      return false
      // const hasProgramNameEditList = [
      //   ...this.box1C01And1H01DeviceInfoList,
      //   ...this.box1D01DeviceInfoList,
      //   ...this.box1E01And1I01DeviceInfoList,
      //   ...this.box1F01And1G01DeviceInfoList
      // ]
      // return hasProgramNameEditList.includes(this.getDeviceInfo(deviceId))
    },
    // 判断跳段时是否能下发段号
    judgeJumpStepCanIssuedInstructionStartStepId(deviceId) {
      return false
      // const deviceInfo = this.getDeviceInfo(deviceId)
      // const canIssuedInstructionDeviceInfoList = [
      //   ...this.box1C01And1H01DeviceInfoList,
      //   ...this.box1D01DeviceInfoList,
      //   ...this.box1E01And1I01DeviceInfoList,
      //   ...this.box1F01And1G01DeviceInfoList
      // ]
      // return canIssuedInstructionDeviceInfoList.includes(deviceInfo)
    },
    // 获取程序编辑配置
    getProgramConfig(deviceId) {
      const deviceInfo = this.getDeviceInfo(deviceId)
      return programConfig[deviceInfo + 'ProgramConfig'] ?? []
    },
    // 获取设备监控台箱子模式为null的网格列表
    getDeviceMonitoringLabModeNullGridList(deviceId) {
      const deviceInfo = this.getDeviceInfo(deviceId)

      let gridList = []
      // if (this.G101DeviceInfoList.includes(deviceInfo)) {
      //   gridList = G101LabModeNullGridList
      // }

      return gridList
    },
    // 获取程序控制按钮列表
    getProgramButtonList(deviceId) {
      const deviceInfo = this.getDeviceInfo(deviceId)
      return ButtonList['box' + deviceInfo + 'ProgramButtonList'] ?? []
    },
    // 获取定值控制按钮列表
    getConstantButtonList(deviceId) {
      const deviceInfo = this.getDeviceInfo(deviceId)
      return ButtonList['box' + deviceInfo + 'ConstantButtonList'] ?? []
    },
    // 获取设备驱动
    getDeviceInfo(deviceId) {
      return deviceId.slice(0, 4)
    },
    // 设置网格列表
    setGridList(gridList, needSetGridList) {
      for (const needSetGridItem of needSetGridList) {
        let needSetGridItemIsExistGridList = false
        for (const gridItem of gridList) {
          if (gridItem.dataName === needSetGridItem.dataName) {
            needSetGridItemIsExistGridList = true
            break
          }
        }
        if (!needSetGridItemIsExistGridList) {
          gridList.push(needSetGridItem)
        }
      }
    }
  }
}
